/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Controleur;

import DAO.DAOException;
import DAO.DAOFactory;
import DAO.VeloDAOmysql;
import DAO.VeloDao;
import Modele.Velo;
import Vue.VeloForm;
import java.util.Date;
import javax.swing.JOptionPane;

/**
 *
 * @author 20cent
 */
public class VeloFormControleur {

    private VeloForm vue;
    private Velo velo;

    public VeloFormControleur(VeloForm vue) {
        this.vue = vue;
    }
    
    public void enregistrer(Velo nvVelo) {

        velo = nvVelo;
        java.awt.EventQueue.invokeLater(new Runnable() {
            
            @Override
            public void run() {
                try {
                    VeloDao dao = new VeloDAOmysql(DAOFactory.getInstance());
                    dao.save(velo);
                    JOptionPane.showMessageDialog(vue, "Insertion réalisée avec succès");
                } catch (DAOException e) {
                    JOptionPane.showMessageDialog(vue,
                            e.getMessage(), "Erreur", JOptionPane.WARNING_MESSAGE);
                } catch (Exception e) {
                    JOptionPane.showMessageDialog(vue,
                            "Une erreur s'est produite à l'insertion !", "Erreur", JOptionPane.WARNING_MESSAGE);
                }
                velo.setMDateEntree(new Date());
                nemovelo.NemoVelo.velos.add(velo);
                vue.dispose();
            }
        });
    }
}
